package cn.itcast.nems.oldems.service.impl;

import cn.itcast.nems.oldems.dao.entiry.StudentExtend;
import cn.itcast.nems.oldems.dao.mapper.StudentExtendMapper;
import cn.itcast.nems.oldems.dto.StudentExtendDto;
import cn.itcast.nems.oldems.service.StudentExtendService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class StudentExtendServiceImpl implements StudentExtendService {

    private final StudentExtendMapper studentExtendMapper;

    @Override
    public StudentExtendDto findById(Integer id) {
        var ext = studentExtendMapper.selectById(id);
        if (ext == null) {
            return null;
        }
        var dto = new StudentExtendDto();
        dto.setId(ext.getId());
        dto.setLivingProvince(ext.getLivingProvince());
        dto.setLivingCity(ext.getLivingCity());
        dto.setCurrentStatus(ext.getCurrentStatus());
        dto.setJobIntention(ext.getJobIntention());
        dto.setStatus(ext.getStatus());
        return dto;
    }

    @Override
    public int saveOrUpdate(StudentExtendDto dto) {
        var d = new StudentExtend();
        d.setId(dto.getId());
        d.setLivingProvince(dto.getLivingProvince());
        d.setLivingCity(dto.getLivingCity());
        d.setCurrentStatus(dto.getCurrentStatus());
        d.setJobIntention(dto.getJobIntention());
        d.setStatus(dto.getStatus());
        //
        var v = studentExtendMapper.selectById(d.getId());
        if (v == null) {
            return studentExtendMapper.insert(d);
        } else {
            return studentExtendMapper.updateById(d);
        }
    }

}
